package com.example.tourism.utils.mail;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class SendMail {
    //  控制台打印调试信息

    private  String fromMail = "2826079730@qq.com";
    private String toMail;
    private String content;
    public SendMail(String toMail, String content) {
        this.toMail = toMail;
        this.content = content;
    }


    public void sendMineMessage()  {
        //	创建Session会话
        Session session = JavaMailUntil.createSession();
        System.out.println("进入发送邮件");
        //	创建邮件对象
        MimeMessage mimeMessage = new MimeMessage(session);
        try {
            mimeMessage.setFrom(new InternetAddress(fromMail));  //发送者
            mimeMessage.setText("你的邮箱验证码：" + content+"   \n 在3分钟以内有效！如果不是你亲自操作，请忽略这个消息！不要泄露验证码给其他人qwq.");
            mimeMessage.setSubject("去哪儿~~~");
            mimeMessage.setRecipient(Message.RecipientType.TO,new InternetAddress(toMail));
            Transport.send(mimeMessage);
        } catch (Exception e) {
          e.printStackTrace();
        }


    }


    public void sendMineMessageID()  {
        //	创建Session会话
        Session session = JavaMailUntil.createSession();

        //	创建邮件对象
        MimeMessage mimeMessage = new MimeMessage(session);
        try {
            mimeMessage.setFrom(new InternetAddress(fromMail));  //发送者
            mimeMessage.setText("注册成功！！！你的用户UID为：" + content );
            mimeMessage.setSubject("TD博客");
            mimeMessage.setRecipient(Message.RecipientType.TO,new InternetAddress(toMail));
            Transport.send(mimeMessage);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }


    }


    public void sendMineMessageID2()  {
        //	创建Session会话
        Session session = JavaMailUntil.createSession();

        //	创建邮件对象
        MimeMessage mimeMessage = new MimeMessage(session);
        try {
            mimeMessage.setFrom(new InternetAddress(fromMail));  //发送者
            mimeMessage.setText("重置密码成功！！！你的用户UID为：" + content );
            mimeMessage.setSubject("TD博客");
            mimeMessage.setRecipient(Message.RecipientType.TO,new InternetAddress(toMail));
            Transport.send(mimeMessage);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }


    }




}
